$(function () {
  init();
})
// 初始化
function init(){
    var id = getParam("id");
    // 确定
    var ajax = new $ax("/leaderschedule/queryID", function (data) {
        // 成功
        if (data.status == "true") {

           // window.location.reload();
            var leaderschedule = data.leaderschedule;
            $("#weekDate").val(formatDateTimeYMDHM(leaderschedule.weekDate));
            $("#workArrangement").val(leaderschedule.workArrangement);
            $("#weekTime").val(formatDateTimeYMDHM(leaderschedule.weekTime));
            $("#place").val(leaderschedule.place);
            $("#managingLeader").val(leaderschedule.managingLeader);
            $("#leadOffice").val(leaderschedule.leadOffice);

        } else {
            alert("查看失败");
        }

    }, function (data) {
        // 失败
        alert("访问失败");
        errorAjax();
        alert("查看失败");
    });

    ajax.setToken(cookie.get("token"));
    ajax.set("id", id);
    ajax.start();
}

function submit2(){
    var id = getParam("id");
    var weekDate = $("#weekDate").val();

    var workArrangement = $("#workArrangement").val();

    var weekTime = $("#weekTime").val();

    var required = $("#required").val();

    var managingLeader = $("#managingLeader").val();

    var leadOffice = $("#leadOffice").val();


    var ajax = new $ax("/leaderschedule/updateID", function (data) {
        // 成功
        if (data.status == "true") {
            alert("更新成功");
            window.location.href='leaderSchedule.html';
        } else {
            // mui.alert(data.message);
            alert("更新失败");
        }

    }, function (data) {
        // 失败
        alert("访问失败");
        errorAjax();
        alert("更新失败");
    });

    ajax.setToken(cookie.get("token"));
    ajax.set("id",id);
    ajax.set("weekDate",weekDate);
    ajax.set("workArrangement",workArrangement);
    ajax.set("weekTime",weekTime);
    ajax.set("required",required);
    ajax.set("managingLeader",managingLeader);
    ajax.set("leadOffice",leadOffice);
    ajax.start();
}

/**
 * 获取指定的URL参数值
 * URL:http://www.xxxxxxx.com/index?name=tyler
 * 参数：paramName URL参数
 * 调用方法:getParam("name")
 * 返回值:tyler
 */
function getParam(paramName) {
    paramValue = "", isFound = !1;
    if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
        arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
        while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
    }
    return paramValue == "" && (paramValue = null), paramValue
}


//return y + '-' + m + '-' + d +' '+h+':'+minute;
function formatDateTimeYMDHM(inputTime) {
    var date = new Date(inputTime);
    var y = date.getFullYear();
    var m = date.getMonth() + 1;
    m = m < 10 ? ('0' + m) : m;
    var d = date.getDate();
    d = d < 10 ? ('0' + d) : d;
    var h = date.getHours();
    h = h < 10 ? ('0' + h) : h;
    var minute = date.getMinutes();
    var second = date.getSeconds();
    minute = minute < 10 ? ('0' + minute) : minute;
    second = second < 10 ? ('0' + second) : second;
    // return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second;
    return y + '-' + m + '-' + d +' '+h+':'+minute;
};